package com.googlecode.horncomb.orm.ibatis.type.handler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.ibatis.sqlmap.engine.type.BaseTypeHandler;

/**
 * @author Daniel
 * @version $LastChangedRevision: 95 $
 */
public class LongTypeHandler extends BaseTypeHandler {

	/**
	 * @see com.ibatis.sqlmap.engine.type.TypeHandler#getResult(java.sql.ResultSet,
	 *      java.lang.String)
	 */
	public Object getResult(ResultSet rs, String columnName)
			throws SQLException {
		if (rs.wasNull()) {
			return null;
		} else {
			return rs.getString(columnName);
		}
	}

	/**
	 * @see com.ibatis.sqlmap.engine.type.TypeHandler#getResult(java.sql.ResultSet,
	 *      int)
	 */
	public Object getResult(ResultSet rs, int columnIndex) throws SQLException {
		if (rs.wasNull()) {
			return null;
		} else {
			return rs.getString(columnIndex);
		}
	}

	/**
	 * @see com.ibatis.sqlmap.engine.type.TypeHandler#getResult(java.sql.CallableStatement,
	 *      int)
	 */
	public Object getResult(CallableStatement cs, int columnIndex)
			throws SQLException {
		if (cs.wasNull()) {
			return null;
		} else {
			return cs.getString(columnIndex);
		}
	}

	/**
	 * @see com.ibatis.sqlmap.engine.type.TypeHandler#setParameter(java.sql.PreparedStatement,
	 *      int, java.lang.Object, java.lang.String)
	 */
	public void setParameter(PreparedStatement ps, int i, Object parameter,
			String jdbcType) throws SQLException {
		ps.setString(i, (String) parameter);
	}

	/**
	 * @see com.ibatis.sqlmap.engine.type.TypeHandler#valueOf(java.lang.String)
	 */
	public Object valueOf(String s) {
		return s;
	}

}
